package com.yzkj.siot.controller;

import com.yzkj.siot.annotation.Permission;
import com.yzkj.siot.annotation.WebLog;
import com.yzkj.siot.base.BaseController;
import com.yzkj.siot.domain.TenantDevice;
import com.yzkj.siot.facade.DeviceFacade;
import com.yzkj.siot.result.PageParams;
import com.yzkj.siot.result.PageResponse;
import com.yzkj.siot.type.ApiType;
import com.yzkj.siot.type.PermissionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 设备
 * 前端控制器
 * </p>
 *
 * @author skye
 * @since 2021-11-07
 */
@RestController
@RequestMapping("/device")
public class DeviceController extends BaseController {

    @Autowired
    DeviceFacade facade;

    @WebLog(type = ApiType.DELETE)
    @Permission(type = PermissionType.TENANT)
    @DeleteMapping("remove")
    public TenantDevice remove(@RequestParam int id) {

        return this.facade.remove(id);
    }

    @WebLog(type = ApiType.SAVE_OR_UPDATE)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("saveOrUpdate")
    public TenantDevice saveOrUpdate(@RequestBody TenantDevice entity) {

        return this.facade.saveOrUpdate(entity);
    }

    @WebLog(type = ApiType.READ)
    @Permission(type = PermissionType.TENANT)
    @GetMapping("queryOne")
    public TenantDevice queryOne(@RequestParam int id) {

        return this.facade.queryOne(id);
    }

    @WebLog(type = ApiType.READ)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("page")
    public PageResponse<TenantDevice> page(@RequestBody PageParams<TenantDevice> pageParams) {

        return this.facade.page(pageParams);
    }

    @WebLog(type = ApiType.DELETE)
    @Permission(type = PermissionType.TENANT)
    @PostMapping("batchRemove")
    public Boolean batchRemove(@RequestBody List<Integer> idList) {

        return this.facade.batchRemove(idList);
    }

    /**
     * 根据设备唯一编码获取设备信息
     *
     * @param uniqueCode 设备唯一编码
     * @return {@link TenantDevice}
     */
    @WebLog(type = ApiType.READ)
    @GetMapping("queryOneByUniqueCode")
    public TenantDevice queryOneByUniqueCode(String uniqueCode) {

        return facade.queryOneByUniqueCode(uniqueCode);
    }
}

